SwitchCompat
(SESL variant) SwitchCompat is a complete backport of the core Switch widget that brings the visuals and functionality of the toggle widget to older versions of the Android platform. Unlike other widgets in this package, SwitchCompat is not automatically used in layouts that include the <Switch>
element. Instead, you need to explicitly use <androidx.appcompat.widget.SwitchCompat>
and the matching attributes in your layouts.
The thumb can be tinted with setThumbTintList and setThumbTintMode APIs as well as with the matching XML attributes. The track can be tinted with setTrackTintList and setTrackTintMode APIs as well as with the matching XML attributes.
Supported attributes include:
- textOn
- textOff
- switchMinWidth
- switchPadding
- switchTextAppearance
- thumb
- thumbTextPadding
- track
- thumbTint
- thumbTintMode
- trackTint
- trackTintMode
For more information, see the Toggle Buttons guide.
Inheritors
Constructors
Link copied to clipboard
Construct a new Switch with default styling.
Construct a new Switch with default styling, overriding specific style attributes as requested.
constructor(@NonNull context: @NonNull Context, @Nullable attrs: @Nullable AttributeSet, defStyleAttr: Int)
Construct a new Switch with a default style determined by the given theme attribute, overriding specific style attributes as requested.
Functions
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Indicates whether the on/off text should be displayed.
Link copied to clipboard
Returns whether the track should be split by the thumb.
Link copied to clipboard
Get the minimum width of the switch in pixels.
Link copied to clipboard
Get the amount of horizontal padding between the switch and the associated text.
Link copied to clipboard
Returns the text displayed when the button is not in the checked state.
Link copied to clipboard
Returns the text displayed when the button is in the checked state.
Link copied to clipboard
Get the drawable used for the switch "thumb" - the piece that the user can physically touch and drag along the track.
Link copied to clipboard
Get the horizontal padding around the text drawn on the switch itself.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Get the drawable used for the track that the switch slides within.
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Configure emoji fallback behavior using EmojiCompat.
Link copied to clipboard
Link copied to clipboard
Sets whether the on/off text should be displayed.
Link copied to clipboard
Specifies whether the track should be split by the thumb.
Link copied to clipboard
Set the minimum width of the switch in pixels.
Link copied to clipboard
Set the amount of horizontal padding between the switch and the associated text.
Link copied to clipboard
Sets the switch text color, size, style, hint color, and highlight color from the specified TextAppearance resource.
Link copied to clipboard
Sets the typeface in which the text should be displayed on the switch.
Sets the typeface and style in which the text should be displayed on the switch, and turns on the fake bold and italic bits in the Paint if the Typeface that you provided does not have all the bits in the style that you specified.
Link copied to clipboard
Sets the text displayed when the button is not in the checked state.
Link copied to clipboard
Sets the text displayed when the button is in the checked state.
Link copied to clipboard
Set the drawable used for the switch "thumb" - the piece that the user can physically touch and drag along the track.
Link copied to clipboard
Set the drawable used for the switch "thumb" - the piece that the user can physically touch and drag along the track.
Link copied to clipboard
Set the horizontal padding around the text drawn on the switch itself.
Link copied to clipboard
Applies a tint to the thumb drawable.
Link copied to clipboard
Specifies the blending mode used to apply the tint specified by setThumbTintList} to the thumb drawable.
Link copied to clipboard
Set the drawable used for the track that the switch slides within.
Link copied to clipboard
Set the drawable used for the track that the switch slides within.
Link copied to clipboard
Applies a tint to the track drawable.
Link copied to clipboard
Specifies the blending mode used to apply the tint specified by setTrackTintList to the track drawable.